<template>
	<view>
		<navbar title="上架商品" :autoBack="true">
			<view class="" slot='rightbtn'>
				<u-button color="#3262FD" @click="navto('/pages/goods/release')"
					:customStyle='{width:"140rpx",height:"56rpx",margin:"0",padding:0,borderRadius:"10rpx",fontSize:"28rpx",color:"#fff"}'>上传商品</u-button>
			</view>
		</navbar>
		<view class="con">
			<scroll-view scroll-y="true" class="scbox">
				<view class="orderlist" v-if='loading'>
					<view class="orderlist__item" v-for="(item,index) in goodslist" :key="index">

						<view class="u-flex">
							<image :src="URL(item.image)" class="orderlist__item__pic" mode="aspectFill"></image>
							<view class="" style="flex: 1;">
								<view class="orderlist__item__name">
									{{item.name}}
									<view class="orderlist__item__status" v-if="item.status==1">
										未审核
									</view>
									<view class="orderlist__item__status" v-if="item.status==2">
										已上架
									</view>
								</view>
								<view class="u-flex u-flex-y-center u-flex-between">
									<view class="orderlist__item__time">
										{{$u.timeFormat(item.createtime, 'yyyy-mm-dd hh:MM:ss')}}
									</view>
									<!-- <view class="orderlist__item__num">
										{{item.price}}
									</view> -->
								</view>
								<view class="u-flex u-flex-items-end u-flex-between" style="margin-top: 30rpx;">
									<view class="orderlist__item__price">
										<text style="font-size: 24rpx;">￥</text>{{item.price}}
									</view>
									<view class="u-flex u-flex-y-center">
										<u-button color="#3262FD" @click="navto('/pages/goods/edit?id='+item.id)"
											:customStyle='{width:"86rpx",height:"56rpx",marginLeft:"16rpx",padding:0,borderRadius:"10rpx",fontSize:"28rpx",color:"#fff"}'>编辑</u-button>
										<u-button color="#3A4E6D" @click="del(item)"
											:customStyle='{width:"86rpx",height:"56rpx",marginLeft:"16rpx",padding:0,borderRadius:"10rpx",fontSize:"28rpx",color:"#fff"}'>删除</u-button>

									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<u-loading-icon :show='!loading'></u-loading-icon>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import goods from '@/api/_goods.js'
	export default {
		data() {
			return {
				goodslist:[],
				loading:false
			};
		},
		methods:{
			getlist(){
				this.loading=false
				goods.getGoods({user_id:uni.getStorageSync('88ffuserinfo').id}).then(res=>{
					this.loading=true
					if(res.data.code==1){
						this.goodslist=res.data.data
					}
				})
			},
			del(item){
				let _this=this
				uni.showModal({
					title:'提示',
					content:'确定删除该商品？',
					success(r) {
						if(r.confirm){
							goods.delete({id:item.id}).then(res=>{
								if(res.data.code==1){
									uni.$u.toast('删除成功')
									setTimeout(()=>{
										_this.getlist()
									},1000)
								}
							})
						}
					}
				})
			}
		},
		onShow() {
			this.getlist()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f3f7;
	}

	.con {
		padding: 20rpx 0 0;

		.orderlist {
			padding: 0 30rpx 50rpx;

			&__item {
				padding: 30rpx;
				background: #FFFFFF;
				border-radius: 30rpx;
				margin-bottom: 28rpx;

				&__status {
					width: 97rpx;
					height: 47rpx;
					background: #BECDE1;
					border-radius: 24rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 22rpx;
					color: #3A4E6D;
					line-height: 22rpx;
				}

				&__pic {
					width: 179rpx;
					height: 176rpx;
					background: #4CD3C5;
					border-radius: 26rpx;
					margin-right: 26rpx;
				}

				&__name {
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #010101;
					line-height: 46rpx;
					margin-bottom: 16rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				&__time {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #59698C;
					line-height: 24rpx;
				}

				&__num {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #59698C;
					line-height: 24rpx;
					display: flex;
					align-items: center;

					&__chen {
						width: 11rpx;
						height: 10rpx;
						margin-right: 5rpx;
					}
				}

				&__price {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 33rpx;
					color: #F94405;
					line-height: 24rpx;

				}
			}
		}
	}
</style>